from google.appengine.api import users
from google.appengine.ext import db
from google.appengine.ext import webapp

from listmodel import ListModel

class NewListRequestHandler(webapp.RequestHandler):
    def post(self):
        # Get the Title for the New List        
        new_list_title = self.request.get('title')
        if ( new_list_title ):
            # Create a New List with the Title and the Current User as Owner
            new_list = ListModel(title = new_list_title, owner = users.get_current_user())
            # Store in the DB
            new_list.put()
            # Redirect to the "list/view" of this new List
            self.redirect("/list/view/" + unicode(new_list.key().id()))
        else:
            # No Title was given, so redirect to the Main page
            self.redirect('/')